<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %><%--
  Created by IntelliJ IDEA.
  User: Admin
  Date: 9/23 0023
  Time: 18:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<!--
必须有一个和表单Path 所对应的Bean ;(空的) 就在代码中new 出来一个;
 map.put("employee", new Employee());
SpringMVC 认为 表单一定会回显;回到 Request 中查找Bean ,来匹配表单值;
配置: modelAttribute="employee"

可以通过 modelAttribute 属性指定绑定的模型属性，若
没有指定该属性，则默认从 request 域对象中读取
command 的表单 bean，如果该属性值也不存在，则会
发生错误。
-->
<form:form action="${pageContext.request.contextPath}/addEmp" method="post" modelAttribute="employee">
    <form:errors path="*"/><br><br>
    <c:if test="${requestScope.employee.id==null }">
        LastName:<form:input path="lastName"/>
        <form:errors path="lastName"/><br><br>
    </c:if>
    <c:if test="${requestScope.employee.id !=null}">
        <form:hidden path="id"/>
    </c:if>

    Email:<form:input path="email"/>
    <form:errors path="email"/><br><br>
    <%
        Map<String, String> genders = new HashMap<>();
        genders.put("1", "Female");
        genders.put("0", "Male");
        request.setAttribute("genders", genders);
    %>
    Gender:<form:radiobuttons path="gender" items="${genders}"/><br><br>
    Department:<form:select path="department.id" items="${requestScope.departments}"
                            itemLabel="departmentName" itemValue="id"/><br><br>
    Birth:<form:input path="birth"/>
    <form:errors path="birth"/><br><br>
    Salary:<form:input path="salary"/><br><br>
    <input type="submit" value="提交"/>
</form:form>

</body>
</html>
